package com.jt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jt.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**继承时必须添加泛型，该泛型必须与表关联
 * MP提供了强大的单表CRUD操作，多表操作自己写*/
public interface UserMapper extends BaseMapper<User> {
    User findUserByUP(User user);

    @Select("select count(1) from user")
    long findTotal();

    //只支持单只传参，封装为map集合
    List<User> findUserList(@Param("start") int start,@Param("size") int size,@Param("query") String query);

    @Insert("insert into user (id,username,password,phone,email,status,created,updated) values(null,#{username}" +
            ",#{password},#{phone},#{email},#{status},#{created},#{updated})")
    void saveUserById(User user);

    @Update("update user set status=#{status} where id=#{id}")
    void status(User user);

    //修改页面原有信息的回显
    @Select("select * from user where id=#{id}")
    User findUserById(Integer id);
}
